// @ts-nocheck

import Vue from 'vue'
import Router from 'vue-router'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// import { getToken } from '@/utils/token'
// import AdminLayout from '@/layouts/admin'

Vue.use(Router)

export function createRouter(ssrContext, createDefaultRouter, routerOptions, config) {
  const options = routerOptions || createDefaultRouter(ssrContext, config).options

  // options.routes.push({
  //   path: '/admin',
  //   name: 'admin',
  //   component: AdminLayout,
  //   children:
  // })

  // console.log(options.routes)
  const router = new Router({
    ...options,
    routes: fixRoutes(options.routes),
  })

  // router.beforeEach((to, from, next) => {
  //   if (process.client) {
  //     const hasToken = Boolean(getToken())
  //     console.log(hasToken)
  //     if (hasToken) {
  //       next()
  //     } else {
  //       const isAdmin = /^\/admin/.test(to.path)
  //       console.log(isAdmin)
  //       if (isAdmin) {
  //         next(`/login`)
  //       } else {
  //         next()
  //       }
  //     }
  //   } else {
  //     next()
  //   }
  // })

  return router
}

function fixRoutes(defaultRoutes) {
  // default routes that come from `pages/`
  return defaultRoutes // .filter(...).map(...)
}
